import { SubjectComponent } from "../../../../core/subject";
import { Random } from "../../../../core/utils";

const { ccclass, property } = cc._decorator;

@ccclass
export default class QuickTalkItem extends SubjectComponent {
    @property(cc.Label)
    lb: cc.Label = null;
    @property(cc.Label)
    lbHotKey: cc.Label = null;
    @property(cc.Sprite)
    face: cc.Sprite = null;
    @property(cc.Node)
    bubble: cc.Node = null;
    protected start(): void {
        cc.tween(this.bubble).repeatForever(
            cc.tween(this.bubble)
                .to(Random.range(15,40)/100, { x: 0, y: Random.range(10, 20) })
                .to(Random.range(15,40)/100, { x: Random.range(10, 20), y: 0 })
                .to(Random.range(15,40)/100, { x: 0, y: -Random.range(10, 20) })
                .to(Random.range(15,40)/100, { x: -Random.range(10, 20), y: 0 })
        ).start();
    }
    protected onLoad(): void {
        this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }
    onClick() {
        this.emit("click", this.lb.string);
    }
};